package 优先算法.前缀和.模板前缀和;

/**
 * <a>https://www.nowcoder.com/practice/acead2f4c28c401889915da98ecdc6bf?tpId=230&tqId=2021480&ru=/exam/oj&qru=/ta/dynamic-programming/question-ranking&sourceUrl=%2Fexam%2Foj%3Fpage%3D1%26tab%3D%25E7%25AE%2597%25E6%25B3%2595%25E7%25AF%2587%26topicId%3D196</a>
 */

import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        //1.读入数组
        int n = sc.nextInt(),q = sc.nextInt();
        int[] arr = new int[n+1];
        for(int i = 1;i< arr.length;i++){
            arr[i] = sc.nextInt();
        }
        //2.预处理前缀和数组
        long[] dp = new long[n+1];//防止加和溢出用long
        for(int i = 1;i < dp.length;i++){
            dp[i] = dp[i-1]+arr[i];
        }

        //3.使用前缀和数组
        while(q>0){
            int l = sc.nextInt(),r = sc.nextInt();
            System.out.println(dp[r] - dp[l-1]);
            q--;
        }
    }
}
